home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / June 96 / Re Proper way to add font m < prev    next >
Encoding:
Internet Message Format  |  1996-12-03  |  2.2 KB  |  [TEXT/ttxt]

  1. Subject:     Re: Proper way to add font m
  2. Sent:        6/24/96 5:18 PM
  3. Received:    6/24/96 5:51 PM
  4. From:        Mary Boetcher, mary_boetcher@quickmail.apple.com
  5. Reply-To:    ODF Interest, ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8. Mail*LinkĀ® SMTP               RE>Proper way to add font menu?
  9.  
  10. Here is some code from my test part that creates and manages a font menu. 
  11. You should define a range of command numbers to represent the font menu items.
  12.  
  13. #define cFirstFontCommand    cMyLastCommand + 1
  14. // Subsequent command numbers used by fonts
  15.  
  16. void AddFontsToMenu(Environment* ev, FW_CPullDownMenu* menu)
  17. {
  18.     short count = 0;
  19.     FW_CFontIterator fontIter;
  20.     FW_CString fontName;
  21.     ODCommandID commandID = cFirstFontCommand;
  22.     for (fontName = fontIter.First(); fontIter.IsNotComplete(); fontName = fontIter.Next())
  23.     {
  24.         menu->AppendTextItem(ev, fontName, commandID+count);
  25.         count++;
  26.     }
  27.     gFontCount = count;
  28. }
  29.  
  30. FW_Boolean CMyEditView::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  31.                                       FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  32. {
  33.     if (hasMenuFocus)
  34.     {
  35.         //-- Enable all items in the Font menu
  36.         ODCommandID c = cFirstFontCommand;
  37.         for (short i=0; i < gFontCount; c++, i++)
  38.             menuBar->EnableAndCheckCommand(ev, c, true, false);
  39.  
  40.         //-- Put a check in front of the current font
  41.         c = GetCurrentFontCmd(ev, menuBar);
  42.         if (c != 0)
  43.             menuBar->CheckCommand(ev, c, true);
  44.     }
  45.     
  46.     return FW_CEditView::DoAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  47. }
  48.  
  49. ODCommandID CMyEditView::GetCurrentFontCmd(Environment* ev, FW_CMenuBar* menuBar)
  50. {
  51.     ODCommandID result = 0;
  52.  
  53.     ODCommandID c = cFirstFontCommand;
  54.     FW_CString fontName;
  55.     for (short i=0; i < gFontCount; i++, c++)
  56.     {
  57.         menuBar->GetItemString(ev, c, fontName);
  58.         if (fontName == fFontName)
  59.         {
  60.             result = c;
  61.             break;
  62.         }
  63.     }
  64.  
  65.     return result;    // could be 0
  66. }
  67.  
  68. FW_Boolean CMyEditView::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  69. {
  70.     FW_Boolean menuHandled = true;
  71.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  72.     
  73.     if (cFirstFontCommand <= id && id < cFirstFontCommand+gFontCount)
  74.     {
  75.         this->CommandToString(ev, id, fFontName);
  76.         this->DoSetFont(ev);
  77.         return menuHandled;
  78.     }
  79.     ...
  80. }
  81.  
  82. Mary Boetcher
  83. ODF Person
  84.